// import { message } from "@/utils/message";
import { transformI18n } from "@/plugins/i18n";
import { getHomeData } from "@/api/home";

import { reactive, ref, onMounted } from "vue";
// refreshCallback?: () => void
export function useRole() {
  const form = reactive({
    customerName: "",
    shortName: "",
    mobile: "",
    remark: ""
  });

  const isShow = ref(false);
  const loading = ref(false);

  const homeData = ref();
  const product = ref();
  const deviceInfo = ref();
  const interfaces = ref();
  // 通讯接口读到的数据
  // 拿首页所有的数据
  async function onSearch() {
    loading.value = true;
    setTimeout(() => {
      loading.value = false;
    }, 500);
    const { data } = await getHomeData();
    homeData.value = data;
    product.value = data.product;
    deviceInfo.value = data.deviceInfo;
    interfaces.value = data.interfaces;
  }

  const resetForm = formEl => {
    if (!formEl) return;
    formEl.resetFields();
    onSearch();
  };

  const filterMethod = (query: string, node) => {
    return transformI18n(node.title)!.includes(query);
  };

  onMounted(async () => {
    onSearch();
  });

  return {
    form,
    isShow,
    loading,
    onSearch,
    resetForm,
    filterMethod,
    transformI18n,
    homeData,
    product,
    deviceInfo,
    interfaces
  };
}
